{% extends "base.html" %}

{% block title %}Flasky{% endblock %}

{% block page_content %}
    <div class="page-header"><h1>User</h1>
        <p><img class="img-rounded profile-thumbnail"
                src="{{ user.gravatar(size=256) }}"></p>
        <div class="profile-header">
            {% if user.name or user.location %}
                <p>
                    {% if user.name %}{{ user.name }}{% endif %}
                    {% if user.location %}
                        From
                        <a href="http://api.map.baidu.com/geocoder?address={{ user.location }}&output=html&src=webapp.baidu.openAPIdemo">
                            {{ user.location }}</a>
                    {% endif %}
                </p>
            {% endif %}
            {% if current_user.is_administrator() %}
                <p><a href="mailto:{{ user.email }}">{{ user.email }}</a></p>
            {% endif %}
            {% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %}
            <p>Member since {{ moment(user.member_since).format('LL') }}.</p>
            <p>Last seen {{ moment(user.last_seen).fromNow(refresh=True) }}.</p>

            <p>
                {% if current_user.can(Permission.FOLLOW)  %}
                {% if not current_user.is_following(user) %}
                {% if user != current_user %}
                    <a href="{{ url_for('.follow', username=user.username) }}" class="btn btn-primary">
                        Follow</a>
                {% endif %}
                {% else %}
                    <a href="{{ url_for('.unfollow', username=user.username) }}" class="btn btn-default">
                        Unfollow</a>
                {% endif %}
                <a href="{{ url_for('.followers', username=user.username) }}">Followers:<span
                        class="badge">{{ user.followers.count() }}</span></a>
                <a href="{{ url_for('.followed_by', username=user.username) }}">Following:
                    <span class="badge">{{ user.followed.count() }}</span>
                </a>
                {% if current_user.is_authenticated and user != current_user
                and user.is_following(current_user) %}
                | <span class="label label-default">Follows you</span>
                {% endif %}
                {% endif %}

            </p>
            <p>
                {% if user == current_user and not current_user.is_administrator() %}
                    <a class="btn btn-default" href="{{ url_for('.edit_profile') }}">Edit Profile</a>
                {% endif %}
                {% if current_user.is_administrator() %}
                    <a class="btn btn-danger" href="{{ url_for('.edit_profile_admin' , id=user.id) }}">
                        Edit Profile [admin]</a>
                {% endif %}
            </p>

        </div>
    </div>
    <div class="post">
        <h3>Posts by {{ user.username }}</h3>
        {% include '_posts.html' %}
    </div>
{% endblock %}